using HelpDeskTool.Entities.Devices;
using HelpDeskTool.Entities;
using System.Globalization;
using System.Text;
using System.Windows.Data;

namespace HelpDeskTool.Converters;

public class WmiInfoConverter : IValueConverter
{
	public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		if (value is not WmiInfo wmiInfo)
			return null;

		var strBuilder = new StringBuilder();

		if (!string.IsNullOrWhiteSpace(wmiInfo.OperatingSystem))
			strBuilder.AppendLine($"OS:\t{wmiInfo.OperatingSystem}");

		if (wmiInfo.Hardware?.Motherboard != null)
			strBuilder.AppendLine($"MB:\t{wmiInfo.Hardware.Motherboard}");

		if (wmiInfo.Hardware?.CPUs?.Length > 0)
			strBuilder.AppendLine($"CPU:\t{string.Join<Device>("\n\t", wmiInfo.Hardware.CPUs)}");

		if (wmiInfo.Hardware?.RAM?.Length > 0)
			strBuilder.AppendLine($"RAM:\t{string.Join<Device>("\n\t", wmiInfo.Hardware.RAM)}");

		if (wmiInfo.Hardware?.StorageDisks?.Length > 0)
			strBuilder.AppendLine($"DEV:\t{string.Join<Device>("\n\t", wmiInfo.Hardware.StorageDisks)}");

		if (wmiInfo.Hardware?.GPUs?.Length > 0)
			strBuilder.AppendLine($"GPU:\t{string.Join<Device>("\n\t", wmiInfo.Hardware.GPUs)}");

		if (wmiInfo.Hardware?.Monitors?.Length > 0)
			strBuilder.AppendLine($"MON:\t{string.Join<Device>("\n\t", wmiInfo.Hardware.Monitors)}");

		if (wmiInfo.Hardware?.NetworkAdapters?.Length > 0)
			strBuilder.AppendLine($"NET:\t{string.Join<Device>("\n\t", wmiInfo.Hardware.NetworkAdapters)}");

		return strBuilder.ToString();
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}
}
